home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import os
- import sys
- import time
- import socket
- import urllib
- import urllib2
- import platform
- import threading
- import wx
- import win32api
- import pywintypes
- if hasattr(sys, 'frozen'):
- import StringIO
- sys.stderr = StringIO.StringIO()
- sys.stdout = StringIO.StringIO()
-
- from spamexperts import se_logging
-
- try:
- from se_config import spamexpertsConfig
- except Exception:
- spamexpertsConfig = None
-
-
- try:
- from spamexperts.LSPControl import LSPControl
- except Exception:
- LSPControl = None
-
-
- try:
- _
- except NameError:
-
- _ = lambda x: x
-
-
- class ReportData(wx.Dialog):
-
- def __init__(self, parent = None):
- wx.Dialog.__init__(self, parent, title = _('Error Report'))
- self.email_label = wx.StaticText(self, label = _('Your email address:'))
- self.email = wx.TextCtrl(self)
- if spamexpertsConfig:
- self.email.SetValue(spamexpertsConfig.user_address)
-
- label = _('Problem description:')
- self.problem_label = wx.StaticText(self, label = label)
- self.problem = wx.TextCtrl(self, size = (-1, 200), style = wx.TE_MULTILINE)
- self.ok = wx.Button(self, wx.ID_OK)
- self.cancel = wx.Button(self, wx.ID_CANCEL)
- sizer = wx.GridBagSizer(5, 5)
- sizer.Add(self.email_label, (0, 0), (1, 1), wx.ALIGN_LEFT | wx.ALL, 5)
- sizer.Add(self.email, (0, 1), (1, 2), wx.EXPAND | wx.ALL, 5)
- sizer.Add(self.problem_label, (1, 0), (1, 1), wx.ALIGN_CENTER | wx.ALL, 5)
- sizer.Add(self.problem, (2, 0), (1, 3), wx.EXPAND | wx.ALL, 5)
- sizer.Add(self.ok, (3, 2), (1, 1), wx.ALIGN_CENTER | wx.ALL, 5)
- sizer.Add(self.cancel, (3, 1), (1, 1), wx.ALIGN_CENTER | wx.ALL, 5)
- self.SetSizerAndFit(sizer)
- self.GetProblem = self.problem.GetValue
- self.GetEmail = self.email.GetValue
-
-
-
- class ErrorReporter(object):
-
- def __init__(self):
- self.taskManager = None
-
-
- def getOSVersion(self):
- sysPlatform = platform.system()
-
- try:
- winVersions = {
- (1, 4, 0): '95',
- (1, 4, 10): '98',
- (1, 4, 90): 'ME',
- (2, 4, 0): 'NT',
- (2, 5, 0): '2K',
- (2, 5, 1): 'XP' }
- winOSdetails = sys.getwindowsversion()
- a = winOSdetails
- winVersion = winVersions[(a[3], a[0], a[1])]
- osVersion = '%s %s (%s.%s.%s %s)' % (sysPlatform, winVersion, a[0], a[1], a[2], a[4])
- except Exception:
- osVersion = 'Non-Windows OS (%s)' % (sysPlatform,)
-
- return osVersion
-
-
- def getTaskManager(self):
- """Returns all data provided by Windows' Task Manager."""
-
- try:
- import win32pdh
- import win32pdhutil
- except ImportError:
- print 'No performance data helper installed'
- self.getting_tasks = 0
- return None
-
-
- try:
- (processinfo, processes) = win32pdh.EnumObjectItems(None, None, 'Process', -1)
- except pywintypes.error:
- self.getting_tasks = 0
- return { }
- except RuntimeError:
- self.getting_tasks = 0
- return { }
-
- self.taskManager = { }
- find_by_name = win32pdhutil.FindPerformanceAttributesByName
- for process in processes:
- for info in processinfo:
-
- try:
- details = find_by_name(process, counter = info)
-
- try:
- self.taskManager[process][info] = details
- except KeyError:
- self.taskManager[process] = {
- info: details }
-
- continue
- except pywintypes.error:
- continue
- continue
-
-
-
-
- self.getting_tasks = 0
- return self.taskManager
-
-
- def getLspInfo(self):
- if LSPControl:
- lspControl = LSPControl()
- return lspControl.getLSPInfo()
- else:
- return 'Could not import LSPControl'
-
-
- def generateReport(self, callback = None, email = None, problem = None):
- if callback:
- callback(5, _('Getting IP'))
-
- old_timeout = socket.getdefaulttimeout()
- socket.setdefaulttimeout(3)
-
- try:
- local_ip = socket.gethostbyname(socket.gethostname())
- except socket.timeout:
- local_ip = '{unknown}'
-
- socket.setdefaulttimeout(old_timeout)
- yield ('Report from', local_ip)
- if email:
- yield ('User email address', email)
- elif spamexpertsConfig:
- address = spamexpertsConfig.user_address
- yield ('User email address', address)
-
- if problem:
- yield ('Problem description', problem)
-
- if callback:
- callback(10, _('Getting OS'))
-
- yield ('OS details', self.getOSVersion())
- if callback:
- callback(15, _('Getting process list'))
-
- self.getting_tasks = time.time()
- get_tasks = threading.Thread(target = self.getTaskManager)
- get_tasks.start()
- while self.getting_tasks:
- if time.time() > self.getting_tasks + 60 * 3:
- self.taskManager = {
- 'Timed out': None }
- break
-
- time.sleep(1)
- if callback:
- callback(20, _('Getting LSPs'))
-
- lspInfo = self.getLspInfo()
- yield ([], []([ lspInfoLine for lspInfoLine in lspInfo.splitlines() ]))
- lsp_log_fn = os.path.join(win32api.GetSystemDirectory(), 'SpamExpertsLSP.txt')
- if os.path.exists(lsp_log_fn):
- log_data = file(lsp_log_fn).read()
- if len(log_data) > 1024 * 1024:
- yield ('LSP Log', 'LSP log file is too large to include.')
- else:
- yield ('LSP Log', log_data)
-
- if callback:
- callback(30, _('Getting IDs'))
-
- if spamexpertsConfig:
- yield ('Fingerprint Database Unique ID', spamexpertsConfig.user_id)
- else:
- yield ('Could not get configuration.', '')
- for i in xrange(1, 5):
- if callback:
- callback(30 + 2 * i, _('Getting log'))
-
- log_fn = os.path.join(se_logging.log_dir, 'SpamExperts%s.log' % (i,))
- if os.path.exists(log_fn):
- log_data = file(log_fn).read()
- if len(log_data) > 1024 * 1024:
- yield ('Log file %s' % (i,), 'Log file is too large to include')
- else:
- yield ('Log file %s' % (i,), log_data)
- len(log_data) > 1024 * 1024
-
- if callback:
- callback(55, _('Getting POP log'))
-
- pop_log_fn = os.path.join(se_logging.log_dir, '_pop3proxy.log')
- if os.path.exists(pop_log_fn):
- log_data = file(pop_log_fn).read()
- if len(log_data) > 1024 * 1024:
- yield ('POP3 Proxy Log', 'Log file is too large to include')
- else:
- yield ('POP3 Proxy Log', log_data)
-
- if callback:
- callback(60, _('Getting IMAP log'))
-
- imap_log_fn = os.path.join(se_logging.log_dir, '_imap4proxy.log')
- if os.path.exists(imap_log_fn):
- log_data = file(imap_log_fn).read()
- if len(log_data) > 1024 * 1024:
- yield ('IMAP4 Proxy Log', 'Log file is too large to include')
- else:
- yield ('IMAP4 Proxy Log', log_data)
-
- if callback:
- callback(65, _('Getting copyfile log'))
-
- copyfile_log_fn = os.path.join(se_logging.log_dir, 'se_copyfile.log')
- if os.path.exists(copyfile_log_fn):
- log_data = file(copyfile_log_fn).read()
- if len(log_data) > 1024 * 1024:
- yield ('copyfile log', 'Log file is too large to include')
- else:
- yield ('copyfile log', log_data)
-
- yield self.get_stats(callback)
-
-
- def get_stats(callback):
- if callback:
- callback(70, _('Getting performance statistics'))
-
-
- try:
- options = options
- import spamexperts.Options
- except Exception:
- return ('Performance Statistics', "Couldn't import options")
-
-
- try:
- message = message
- import spambayes
- (fn, typ) = message.database_type()
- db = message.open_storage(fn, typ, 'r')
- except Exception:
-
- try:
- db.close()
- except:
- pass
-
- return ('Performance Statistics', "Couldn't get message db")
-
-
- try:
- message = message
- import spamexperts
- m_class = message.SEHeaderMessage
- except Exception:
- db.close()
- return ('Performance Statistics', "Couldn't get message class")
-
-
- try:
- se_stats = se_stats
- import spamexperts
- except Exception:
- db.close()
- return ('Performance Statistics', "Couldn't import stats")
-
- statistics = se_stats.SEStats(options, db, m_class)
- stats = []([ a for a, unused in statistics.GetStats() ])
- db.close()
- return ('Performance Statistics', stats)
-
- get_stats = staticmethod(get_stats)
- base_url = 'http://spamexperts.com/cgi-bin/error_receiver.py'
-
- def submit_report(self, callback, email = None, problem = None):
- if email is None or problem is None:
- dlg = ReportData()
- result = dlg.ShowModal()
- if result == wx.ID_CANCEL:
- print 'Cancelled report'
- return (True, 'Cancelled')
-
- email = dlg.GetEmail()
- problem = dlg.GetProblem()
- dlg.Destroy()
-
- report = self.generateReport(callback, email, problem)
- for encoding in ('ascii', 'latin-1', 'koi8-r'):
-
- try:
- report = []([ (title.encode(encoding), data.encode(encoding)) for title, data in report ])
- except UnicodeEncodeError:
- continue
-
- else:
- print >>sys.stderr, 'Could not encode report. Cancelling.'
- return (False, "Couldn't encode")
- callback(75, _('Transmitting'))
-
- try:
- url = urllib2.urlopen(self.base_url, urllib.urlencode(report))
- except (urllib2.HTTPError, urllib2.URLError, socket.error):
- e = None
- print >>sys.stderr, 'Could not submit report', str(e)
- return (False, str(e))
-
- callback(99, _('Complete'))
- print 'Sent report (%s)' % (url.read(),)
- return (True, 'Complete')
-
-
- if __name__ == '__main__':
- e = ErrorReporter()
-
- callback = lambda x, y: pass
- if spamexpertsConfig:
- email = spamexpertsConfig.user_address
- else:
- email = 'unknown@example.com'
- e.submit_report(callback, email, 'copyfile.exe failed.')
-
-